package com.example.a7822.myapplication.shopcart.model;


import com.example.a7822.myapplication.shopcart.beans.GoodBean;
import com.example.a7822.myapplication.shopcart.common.Urls;
import com.example.a7822.myapplication.utils.Logger;

import java.util.List;

/**
 * Created by Flyln on 2016/6/14.
 */
public class GoodModelImpl implements GoodModel {
    private String tag = "GoodModelImpl";
    private Logger logger = Logger.getLogger(GoodModelImpl.class);
    //加载购物车
    @Override
    public void loadCart(String url, final int type , final OnLoadGoodListListener listener) {
        //采用回调的方式异步通知收到的数据
       /* if (SPCartManager.getInstance().getGoodList() != null){
            listener.onLoadGoodsSuccess(SPCartManager.getInstance().getGoodList());
        } else{
            listener.onLoadGoodsFailure("load Cart list failure.",new Exception());
        }*/
    }


    //加载一件商品
    @Override
    public void loadOneGood(String url, List params, final OnLoadGoodListener listener) {
//        OkHttpUtils.ResultCallback<String> callback = new OkHttpUtils.ResultCallback<String>() {
//            @Override
//            public void onSuccess(String response) {
//                GoodBean good = GoodJsonUtils.readJsonGoodBean(response);
////                logger.d("扫描到的商品信息为："+good.toString());
//                listener.onLoadGoodSuccess(good);
//            }
//
//            @Override
//            public void onFailure(Exception e) {
//                listener.onLoadGoodFailure("load news list failure.", e);
//            }
//        };
//        OkHttpUtils.get(url, callback, params);
    }

    /**
     * 获取ID
     *
     * @param type
     * @return
     */
    private String getID(int type) {
        String id;
        switch (type) {
            case 0:
                id = Urls.TOP_ID;
                break;
            default:
                id = Urls.TOP_ID;
                break;
        }
        return id;
    }

    //监听购物车加载
    public interface OnLoadGoodListListener {
        void onLoadGoodsSuccess(List<GoodBean> list);
        void onLoadGoodsFailure(String msg, Exception e);
    }
    //监听商品加载
    public interface OnLoadGoodListener {
        void onLoadGoodSuccess(GoodBean goodBean);
        void onLoadGoodFailure(String msg, Exception e);
    }
}
